﻿package
{
	import com.twothreetwo.events.URLUtilsEvent;
	import com.twothreetwo.jsonLoader.JSONLoader;
	import com.twothreetwo.objectLoader.ObjectLoader;
	import com.twothreetwo.xmlLoader.XMLLoader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import com.twothreetwo.urlUtils.URLUtils;
	import flash.net.URLLoader;
	
	/**
	 * ...
	 * @author 232°Studios | Neil Glenister
	 * @link www.232studios.com
	 */
	public class Main extends Sprite 
	{
		private var object:MovieClip;
		private var json:JSONLoader;
		private var xml:XMLLoader;
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
		}
		
		/**
		 * Load URL
		 */
		private function loadUrl():void
		{
			URLUtils.getURL("http://232studios.com", "_blank");
		}
		
		/**
		 * Load none Cached Url
		 */
		private function loadCacheFreeUrl():void
		{
			var randUrl:String = URLUtils.returnNoCacheUrl("http://232studios.com/index.htm");
			URLUtils.getURL(randUrl, "_blank");
		}
		
		/**
		 * Load Object
		 */
		private function loadObject():void
		{
			object = URLUtils.returnObject("http://wallpaperblog.files.wordpress.com/2007/12/blue_sky_1920.jpg");
			object.addEventListener(URLUtilsEvent.OBJECT_LOADED, objectLoaded);
		}
		
		private function objectLoaded(e:URLUtilsEvent):void
		{
			trace("object loaded");
			this.addChild(object);
		}
		
		/**
		 * Load JSON
		 */
		private function loadJSON():void
		{
			json = URLUtils.returnJSON("http://api.twitter.com/1/statuses/public_timeline.json");
			json.addEventListener(URLUtilsEvent.JSON_LOADED, jsonLoaded);
		}
		
		private function jsonLoaded(e:URLUtilsEvent):void
		{
			trace(json.jsonObject);
		}
		
		/**
		 * Load XML
		 */
		private function loadXML():void
		{
			xml = URLUtils.returnXML("http://232studios.com/labs/?feed=rss2");
			xml.addEventListener(URLUtilsEvent.XML_LOADED, xmlLoaded);
		}
		
		private function xmlLoaded(e:URLUtilsEvent):void
		{
			trace("XML = " + xml.data.length);
		}
	}
	
}